﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ddbs.QE.Message
{
    [Serializable]
    public class QEMessage
    {        
        /// <summary>
        /// //大类; query, control
        /// query type: 
        ///     0: query command; 
        ///     1: query rsponse;
        /// control type:    
        ///     2: online notification command
        ///     3: online response command
        ///     4: offline notification command
        ///     5: offline response command
        /// </summary>
        public int CommandType =0; 
        
        //public string SourceName; //name of source host;
        public string DestinationName;  //name of destination host
        //public string SourceIP;
        //public string DestinationIP;

        //public int MsgContentType;      //message content type
        
        public QueryID QueryID;
       // public QueryID[] children;
        /// <summary>
        /// 转发或者返回的 site name
        /// </summary>
        public string NextDestinationName;

        public string TableName;   //name of table
        public string[] columnNames; //本次查询/查询结果涉及那些字段

        public int OperationType; //0: join, 1: combine; 2: fragment

        public string CommandString;  //Query command string, or control command string
        
        /// <summary>
        /// 返回查询的结果
        /// </summary>
        public System.Data.DataSet DataSet;  //

        public string ToString()
        {
            StringBuilder buf = new StringBuilder();
            buf.Append("CommandType:" + this.CommandType);
            buf.Append("\r\nOperationType:" + this.OperationType);
            buf.Append("\r\nCommandString:" + this.CommandString);
            buf.Append("\r\nDestinationName:" + this.DestinationName);
            buf.Append("\r\nNextDestinationName:" + this.NextDestinationName);
            buf.Append("\r\nTableName:" + this.TableName);
            return buf.ToString() ;
        }
    }

    public class QueryID
    {
        public Guid ParentQueryID;
        public Guid CurrentID;
        public Guid[] ChildID;

        public static Guid GetNewGuid()
        {
            return Guid.NewGuid();
        }

        public string GetQueryKey()
        {
            return string.Format("{0}_{1}", 
                ParentQueryID.ToString(),
                CurrentID.ToString() );
        }

        public static string GetQueryKey(Guid parentID, Guid currentID)
        {
            return string.Format("{0}_{1}",
                parentID.ToString(),
                currentID.ToString());
        }
    }
}
